﻿using System;
using MathematicallySafe.HeadCounter.Data;
using MathematicallySafe.HeadCounter.Data.Common;
using MathematicallySafe.HeadCounter.Services;
using StructureMap;

namespace MathematicallySafe.HeadCounter.ViewModels
{
    public class HeadCountRaiderViewModel : ViewModelBase
    {
        private static readonly IHeadCounterService HeadCounterService = ObjectFactory.GetInstance<IHeadCounterService>();

        private bool _ignore;
        private bool _isNewRaider;
        private string _name;

        public string Name
        {
            get { return _name; }
            set
            {
                _name = value;
                IsNewRaider = !HeadCounterService.Guild.IsMember(_name);
                OnPropertyChanged("Name");
            }
        }

        public CharacterClass Class { get; set; }
        public CharacterRace Race { get; set; }

        public TimeSpan TotalTime { get; set; }
        public TimeSpan WaitTime { get; set; }
        public TimeSpan Offline { get; set; }

        public TimeSpan ActualTime
        {
            get { return TotalTime + WaitTime - Offline; }
        }

        public int ActualMinutes
        {
            get { return Convert.ToInt32(Math.Round(ActualTime.TotalMinutes)); }
        }

        public bool IsNewRaider
        {
            get { return _isNewRaider; }
            set
            {
                _isNewRaider = value;
                OnPropertyChanged("IsNewRaider");
            }
        }

        public bool Ignore
        {
            get { return _ignore; }
            set
            {
                _ignore = value;
                OnPropertyChanged("Ignore");
            }
        }
    }
}